import React, { Component } from 'react'
import Fn1 from './练习child'
class App extends Component {
  state = {
    list: [
      {
        id: 1,
        name: '超级好吃的棒棒糖',
        price: 18.8,
        info: '开业大酬宾，全场8折',
      },
      {
        id: 2,
        name: '超级好吃的大鸡腿',
        price: 34.2,
        info: '开业大酬宾，全场8折',
      },
      {
        id: 3,
        name: '超级无敌的冰激凌',
        price: 14.2,
        info: '开业大酬宾，全场8折',
      },
    ],
  }
  changeMoney = (id, price) => {
    console.log('砍价', id, price)
    this.setState({
      list: this.state.list.map((item) => {
        if (item.id === id) {
          return {
            ...item,
            price: item.price - price,
          }
        } else {
          return item
        }
      }),
    })
  }
  render() {
    return (
      <div>
        <h1>父组件</h1>
        <hr />
        {this.state.list.map((item) => {
          return (
            <Fn1
              title={item.name}
              price={item.price}
              desc={item.desc}
              id={item.id}
              key={item.id}
              changeMoney={this.changeMoney}></Fn1>
          )
        })}
      </div>
    )
  }
}
export default App
